<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            height: 3000px;
        }

        .box {
            display: flex;
        }

        .box img {
            width: 200px;
            height: 200px;
            object-fit: contain;
            margin: 5px;
        }

        .cover {
            position: fixed;
            inset: 0;
            background-color: rgba(0, 0, 0, .6);
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .cover img {
            max-width: 90%;
            min-width: 15%;
            max-height: 90%;
            min-height: 15%;
            object-fit: contain;
        }
    </style>
</head>

<body>
    <div class="box">
        <img src="3.jpg" alt="">
        <img src="3.jpg" alt="">
        <img src="3.jpg" alt="">
    </div>
    <script>

        const iBox = document.querySelector('.box')
        const imgList = document.querySelectorAll('.box img')

        for (let i = 0; i < imgList.length; i++) {
            imgList[i].classList.add('preview')
        }

        iBox.onclick = (e) => {
            if (e.target.className === 'preview') {
                const iCover = document.createElement('div')
                iCover.classList.add('cover')
                iCover.onclick = () => {
                    iCover.remove()
                }

                const innerImg = document.createElement('img')

                innerImg.src = e.target.src

                iCover.appendChild(innerImg)

                document.body.appendChild(iCover)


                iCover.onwheel = (e) => {

                    // console.log(e.wheelDelta);   // 判断滚轮的方向


                    const width = parseFloat(getComputedStyle(innerImg).width)
                    const height = parseFloat(getComputedStyle(innerImg).height)

                    e.preventDefault()
                    if (e.wheelDelta > 0) {
                        innerImg.style.width = width * 1.15 + 'px'
                        innerImg.style.height = height * 1.15 + 'px'
                    }
                    else {
                        innerImg.style.width = width * 0.85 + 'px'
                        innerImg.style.height = height * 0.85 + 'px'
                    }
                    // console.log(width);
                }

            }
        }
    </script>
</body>

</html>